﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using SimpleBlog.Models;
using SimpleBlog.Helpers;
using SimpleBlog.Infrastructure.Repositories;

namespace SimpleBlog.Infrastructure.Database
{
    public class SbInitializer : CreateDatabaseIfNotExists<SbContext>
    {
        protected override void Seed(SbContext context)
        {
            DefaultUsers(context);
            DefaultConfiguration(context);
        }

        private void DefaultUsers(SbContext context)
        {
            var users = new List<User>()
            {
                new User
                {
                    Name = "Administrator",
                    Login = "admin",
                    Password = PasswordHelper.GetHashedPassword("admin"),
                    Email = "admin@domain.com"
                }
            };
            users.ForEach(x => context.Users.Add(x));
        }

        private void DefaultConfiguration(SbContext context)
        {
            var configs = new List<Configuration>()
            {
                new Configuration() 
                { 
                    ConfigKey = "BlogTitle", 
                    ConfigValue = "My Blog", 
                    TextArea = false 
                },
                new Configuration() 
                {
                    ConfigKey = "BlogSubtitle", 
                    ConfigValue = "My Personal WebSite!", 
                    TextArea = false 
                },
                new Configuration() 
                { 
                    ConfigKey = "AboutTitle", 
                    ConfigValue = "About me:", 
                    TextArea = false 
                },
                new Configuration() 
                { 
                    ConfigKey = "AboutText", 
                    ConfigValue = "<p>Test about text.</p><p>HTML Code</p>", 
                    TextArea = true 
                },
                new Configuration() 
                { 
                    ConfigKey = "Copyright", 
                    ConfigValue = "Test Copyright", 
                    TextArea = false 
                },
                new Configuration() 
                { 
                    ConfigKey = "Footer",
                    ConfigValue = "<div class=\"domain\">Test Domain</div><div class=\"hosting\">Test Hosting</div><div class=\"copyright\">Test Copyright &copy; 2011</div>", 
                    TextArea = true 
                },
                new Configuration() 
                { 
                    ConfigKey = "GoogleAnalyticsCode",
                    ConfigValue = string.Empty, 
                    TextArea = false 
                },
                new Configuration() 
                { 
                    ConfigKey = "ReCaptchaPublicKey",
                    ConfigValue = string.Empty, 
                    TextArea = false 
                },
                new Configuration() 
                { 
                    ConfigKey = "ReCaptchaPrivateKey",
                    ConfigValue = string.Empty, 
                    TextArea = false 
                }
            };
            configs.ForEach(x => context.Configurations.Add(x));
        }
    }
}